package com.book.controller;

import com.book.model.dto.*;
import com.book.model.entity.User;
import com.book.service.UserService;
import com.book.util.BaseResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 账号表 前端控制器
 * </p>
 *
 * @author auto
 * @since 2025-04-02 06:38:55
 */
@RestController
@RequestMapping("/user")
@Tag(name = "账号表", description = "账号表相关接口")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation(value = "账号密码登录")
    public BaseResult<?> loginByUserNameAndPassword(@RequestBody AdminLoginDTO adminLoginDTO) {
        return BaseResult.successResult(userService.loginByUserNameAndPassword(adminLoginDTO));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取账号信息")
    public BaseResult<?> getUserById(@PathVariable("id") String id) {
        return BaseResult.successResult(userService.getUserById(id));
    }

    @PostMapping("/wxLogin")
    @ApiOperation(value = "微信登录")
    public BaseResult<?> loginByWx(@RequestBody WxLoginDTO dto) {
        return BaseResult.successResult(userService.loginByWx(dto));
    }

    @PostMapping("/list")
    @ApiOperation(value = "分页获取用户信息")
    public BaseResult<?> getListByPage(@RequestBody UserQueryPageDTO dto) {
        return BaseResult.successResult(userService.getListByPage(dto));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除管理员信息")
    public BaseResult<?> deleteUserAdmin(@PathVariable("id") String id) {
        return BaseResult.successResult(userService.removeById(id));
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加管理员")
    public BaseResult<?> addUserAdmin(@RequestBody User dto) {
        return BaseResult.successResult(userService.addOrUpdateUser(dto));
    }

    @PostMapping("/sendCode/{phone}")
    @ApiOperation(value = "发送短信验证码")
    public BaseResult<?> sendCode(@PathVariable("phone") String phone) {
        return BaseResult.successResult(userService.sendCode(phone));
    }

    @PostMapping("/bindPhone")
    @ApiOperation(value = "绑定手机号")
    public BaseResult<?> bindPhone(@RequestBody BindPhoneDTO dto) {
        return BaseResult.successResult(userService.bindPhone(dto));
    }

    @PostMapping("/pointsGive")
    @ApiOperation(value = "积分转让")
    public BaseResult<?> pointsGive(@RequestBody PointsGiveDTO dto) {
        return BaseResult.successResult(userService.pointsGive(dto));
    }

    @PutMapping("/resetPassword")
    @ApiOperation(value = "重置密码")
    public BaseResult<?> resetPassword(AdminResetDTO dto){
        return BaseResult.successResult(userService.resetPassword(dto));
    }
}
